<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
class SiteMenu extends Model
{
    use SoftDeletes;

    protected $table = "site_menu";

    protected $primaryKey = "menu_id";

    protected $fillable = array(
        'menu_id','parent_id','name','url','description','status','display_order','permision_id'
    );
    protected $dates = ['deleted_at'];

    /**
     * 获取某个父菜单下的所有子菜单列表
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function childrenMenu()
    {
        return $this->hasMany('App\Models\SiteMenu', 'parent_id', 'menu_id');
    }
    
    public function parentMenu()
    {
        return $this->hasOne('App\Models\SiteMenu','menu_id','parent_id');
    }
    
    public static function getSiteMenu($parent_id)
    {
        return DB::table('site_menu')->select('menu_id as cat_id','name as cat_name')->where('parent_id','=',$parent_id)->get();
    }
}

